<%@page contentType="text/html; charset=utf-8" %>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>新建管理区</title>
<script language="JavaScript"  src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript" src="${ctx}/scripts/validation/validation.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/div/common.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/calendar.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/lang/calendar-en.js"></script>
<script language="JavaScript"  src="${ctx}/scripts/jscalendar-1.0/calendar-setup.js"></script>
<link href="${ctx}/scripts/jscalendar-1.0/calendar-blue.css" rel="stylesheet" type="text/css">
<script>
	var ACTION_URL="${ctx}/house_precinctAction.do?";
	var sourceValue;

	//新增
	function add(){
		var url= ACTION_URL + "method=addPrecinct";
		var pars=$('fprecicnt').serialize();
		//校验
		var isTure= $("fprecicnt").fireEvent("onSubmit");
		//ajax提交
		if(isTure){
			closeORopenButton();
		//			alert(url);
			var myAjax = new Ajax.Request(
		                    url,
		                    {method: 'post', parameters: pars, onComplete: showResponseAdd}
		                    );
		}
	}

	//新增操作的响应
	function showResponseAdd(result){
		var obj=findFrame('mainFrame');
		obj.reLoadIFrameList();
		closeORopenButton();
		ajaxSubmitException(result.responseText);
		windowClose();
	}


	//修改
	function edit(){
		var url= ACTION_URL + "method=editPrecinct";
		var pars=$('fprecicnt').serialize();
		//校验
		var isTure= $("fprecicnt").fireEvent("onSubmit");
		//ajax提交
		if(isTure){
			closeORopenButton();
		//			alert(url);
			var myAjax = new Ajax.Request(
		                    url,
		                    {method: 'post', parameters: pars, onComplete: showResponseEdit}
		                    );
		}
	}

	//修改操作的响应
	function showResponseEdit(result){
		var obj=findFrame('mainFrame');
		obj.reLoadIFrameListWithQuery();
		closeORopenButton();
		ajaxSubmitException(result.responseText);
		windowClose();
	}

	function init(){
		sourceValue=$('fprecicnt').serialize();
		if(${isEdit}){
			$('head_title').innerText='${key.modifyPrecinct}';
			$('precinctCode').readOnly=true;
			$('period').readOnly=true;
			$('periodTimeButton').disabled=true;
			Event.observe('btn1_22','click',edit);
		}else{
			$('head_title').innerText='${key.addPrecinct}';
			Event.observe('btn1_22','click',add);
		}
		$('name').validateUrl=ACTION_URL + "method=checkPrecinctName";
		$('precinctCode').validateUrl=ACTION_URL + "method=checkPrecinctName";
	}

	//如果内容有修改，则先提示是否关闭
	function closeWin(){
		var newValue=$('fprecicnt').serialize();
		if(sourceValue==newValue){
			windowClose();
		}else{
			AskConfirmTwo('${key.tipsForCloseWindow}',"PrecinctEditIFrame","afterCloseDo","windowClose");
		}
	}

	//关闭窗口前执行的动作
	function afterCloseDo(){
		if(${isEdit}){
			edit();
		}else{
			add();
		}
	}

	//关闭或打开按钮事件
	function closeORopenButton(){
		$('window_footer').disabled= !$('window_footer').disabled;
		$('btn1_22').disabled= !$('btn1_22').disabled;
		$('btn1_32').disabled= !$('btn1_32').disabled;
	}

	//选择楼栋
	function openSelectBuilding(){
		var url="${ctx}/common_commonAction.do?method=initCommonSelectBuilding";
		var pars="&parentFrameId=PrecinctEditIFrame&precinctId="+'${precinctVO.keyword}';
		top.windowOpen(url+pars, 'selectBuilding', '${key.selectBuilding}', 480, 700, true, "selectBuilding");
	}

	//选择楼栋成功后，将调用本方法
	function selectBuildingInfo(buildingIdStrTemp,buildingNameStrTemp){
		$('buildingNames').value=getStr(buildingNameStrTemp);
		$('buildingIds').value=getStr(buildingIdStrTemp);
	}

	//去除字符串中的最后逗号
	function getStr(str){
		if(str.charAt(str.length-1)==","){
			return str.substring(0,str.length-1);
		}else{
			return str;
		}
	}
</script>
</head>

<body onload="init();">
<form action="" name="fprecicnt"  class="required-validate required">
<input type="hidden" name="oldName" value="${precinctVO.name}" >
<input type="hidden" name="oldPrecinctCode" value="${precinctVO.precinctCode}" >
<input type="hidden" name="keyword" value="${precinctVO.keyword}" >
<input type="hidden" name="manageOrgId" value="${manageOrgVO.keyword}">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle"> <span id="head_title" class="window_head_intext">新建管理区</span></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td class="aux_header_line_1"></td>
  </tr>
  <tr>
    <td class="aux_header_line_2"></td>
  </tr>
  <tr>
    <td valign="middle" class="content"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="container_in_show">
      <tr>
        <td valign="top">
        <div id="tab_Search" >
              <table width="100%" border="0" cellpadding="0" cellspacing="0" id="tab_subMenu1">
                <tr>
                  <td><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">

                      <tr>
                        <td><table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
                          <tr>
                            <td  class="aux_intable_td1">${key.manageorgName}：</td>
                            <td  class="aux_intable_td2">${manageOrgVO.name}</td>
                          </tr>
                          <tr>
                            <td  class="aux_intable_td1">${key.name}：</td>
                            <td  class="aux_intable_require"><input name="name" type="text" class="inputtext required validate-char validate-ajax" relativeId="oldName" validateUrl="" value="${precinctVO.name}" maxlength="100" size="16">                            </td>
                            </tr>
                          <tr>
                            <td class="aux_intable_td1">${key.precinctType}：</td>
                            <td  class="aux_intable_require">
                            	<mypms:Sysrefcode style="width:110px;" className="required" name="precinctTypeId" code="HM_PRECINCT_TYPE" selectValue="${precinctVO.precinctTypeId}"></mypms:Sysrefcode>
                            </td>
                          </tr>
                          <tr>
                            <td class="aux_intable_td1">${key.period}：</td>
			                <td class="aux_intable_require"><input name="period" type="text" class="inputtext required validate-date-yyyymm" value="${precinctVO.period}" size="16" >
				                <img src="${ctx}/images/ico_clock.gif" width="20" height="20" name="periodTimeButton">
			                </td>

                          </tr>
                          <tr>
                            <td class="aux_intable_td1">${key.buildingNames}：</td>
                            <td class="aux_intable_td2"><table border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td>
                                	<input id="buildingNames" name="buildingNames" type="text" readonly="readonly" class="inputtext" value="${precinctVO.buildingNames}"  size="16">
                                	<input name="buildingIds" type="hidden" value="${precinctVO.buildingIds}">
                                </td>
                                <td width="4">&nbsp;</td>
                                <td><a href="#"  onClick="openSelectBuilding();"onFocus="this.blur()"><img src="${ctx}/images/ico_houesno.GIF" alt="${key.selectBuildingTip}" border="0"></a></td>
                              </tr>
                            </table></td>
                            </tr>
							                          <tr>
	                            <td  class="aux_intable_td1">${key.precinctCode}：</td>
	                            <td  class="aux_intable_require"><input name="precinctCode" type="text" class="inputtext required validate-char validate-ajax" relativeId="oldPrecinctCode"  validateUrl="" value="${precinctVO.precinctCode}" maxlength="2" size="16">                            </td>
	                          </tr>


                        </table></td>
                      </tr>

                  </table></td>
                </tr>
              </table>

			</div>
			</div>
		  </td>
      </tr>
    </table>

	</td>
  </tr>
  <tr>
    <td class="window_footer" id="window_footer"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><table border="0" cellpadding="0" cellspacing="0" >
            <tr>
			  <td>&nbsp;</td>
			  <td class="btn_between_space"></td>
              <td class="buttonOffLeft" id="btn1_21"></td>
              <td class="buttonOffMiddle" id="btn1_22" onblur="btn_change(2)" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onClick="closewin();"><img src="${ctx}/images/ico_ok.gif" border="0" align="absmiddle" /> ${key.save}</td>
              <td class="buttonOffRight" id="btn1_23"></td>
            </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0" onClick="closeWin();">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" id="btn1_32" onblur="btn_change(3)" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)"><img src="${ctx}/images/ico_cancel.gif" border="0" align="absmiddle" /> ${key.close}</td>
              <td class="buttonOffRight" id="btn1_33"></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
<script type="text/javascript">
              Calendar.setup(
              {
	              inputField : "period", // ID of the input field
	              ifFormat : "%Y%m", // the date format
	              button : "periodTimeButton", // ID of the button
	              align          :    "Tl",           // alignment (defaults to "Bl")
			      singleClick    :    true,
			      showsTime		 :	  true
              }
              );

</script>
</body>
</html>